package com.talkweb.newproject.admin.controller;

import com.talkweb.newproject.admin.loginlog.dto.LoginlogEntity;
import com.talkweb.newproject.admin.loginlog.service.LoginlogService;
import com.talkweb.newproject.api.model.common.Response;
import com.talkweb.newproject.api.model.common.Status;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by qsf on 2019/5/7.
 */
@RestController
@RequestMapping(value="/loginlog-api")
@Slf4j
public class LoginlogController {
    @Autowired
    private LoginlogService loginlogService;

    /**
     * 保存
     * @param loginlog
     * @return
     * @throws Exception
     */
    @RequestMapping(value="/save",method = RequestMethod.POST)
    public Response save(@RequestBody LoginlogEntity loginlog) {
        Response response = new Response();
        try{
            loginlogService.save(loginlog);
            return response;

        }catch(Exception e) {
            log.error(e.getMessage(),e);
            response.setStatus(Status.FAILD);
            response.setMessage("执行异常,请重试!");
            return response;
        }
    }

    /**
     * 还原
     * @return
     */
    @RequestMapping(value="/rollBackTables",method = RequestMethod.POST)
    public Response rollBackTables() {
        Response result = new Response();
        try {
            loginlogService.rollbackTables();
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            log.error(e.getMessage(),e);
            result.setStatus(Status.FAILD);
            result.setMessage("执行异常,请重试");
            return result;
        }
    }
}
